home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cgazv5n5.arc
/
LIST5.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-23
|
1KB
|
50 lines
/*---------------------------------------- Listing 5 ------
* Demonstration of calling one handler from another.
* See Listing 1 for copyright terms.
*-------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
void FpeHandler ( int Signal, int SubCode );
void main ( void );
void FpeHandler ( int Signal, int SubCode )
{
/*---------------------------------------------------------
* Microsoft C work around to keep handler from recursive
* re-entry. After enjoying the crash (MSC only) ,
* turn on the following line:
*-------------------------------------------------------*/
#ifdef WATCH_MSC_CRASH
signal(SIGFPE, SIG_IGN);
#endif
_fpreset();
printf( "Signal %d, SubCode %d was raised\n",
Signal, SubCode );
raise ( SIGFPE );
/*---------------------------------------------------------
* For demonstration purposes, SIGFPE was explicitly raised
* within the handler. Therefore, the following line is
* NEVER reached
*-------------------------------------------------------*/
#ifdef WATCH_MSC_CRASH
signal(SIGFPE, FpeHandler);
#endif
}
void main ( void )
{
void (*OldHandler) ( int Signal );
float Bill, Gates;
Bill = Gates;
OldHandler = signal ( SIGFPE, FpeHandler );
if ( OldHandler == SIG_ERR )
printf ( "signal failed\n" );
raise ( SIGFPE );
}